Implement rdtscp emulation and rdtscp_aux "support"
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 26 Nov 2009 11:00:49 +0000 (11:00 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 26 Nov 2009 11:00:49 +0000 (11:00 +0000)
commit8978cc08d9353ace405f1a2d65c3fef963432fa6
treec7a9645337cda66669a51bcb5bea6bca9a421fdd
parent05bafb26f1d9ae60aa160a8c58f861a3c4cd08d9
Implement rdtscp emulation and rdtscp_aux "support"

The rdtscp instruction (and the associated TSC_AUX
msr) are present on most recent AMD processors,
and on the Nehalem and future Intel processors.
Cpuid has a bit to detect the presence of this feature.

Xen intentionally does not expose the cpuid rdtscp bit
to PV OS's or to HVM guests, but PV apps can see this
bit and, as a result, may choose to use the rdtscp
instruction.  When a PV guest with such an app is migrated
to a machine that does not have rdtscp support, the
app will get killed due to an invalid op.  Fix this
by emulating the rdtscp instruction.  We also need
to emulate rdtscp in the case where the machine has
rdtscp support, but rdtsc emulation is enabled (which
is unfortunately a different path: a privileged op).

The rdtscp instruction reads the TSC_AUX register which
presumably is set by the OS (and, in the case of
tsc_mode==pvrdtscp, will be set by Xen).  HV Linux
and PV Linux will not set TSC_AUX because the
cpuid rdtscp bit is not propogated by Xen; I'm told that
Windows always sets TSC_AUX to zero.  So for PV guests
running on rdtscp-capable hardware (that don't use
tsc_mode==pvrdtscp), always set TSC_AUX to zero.

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
xen/arch/x86/time.c
xen/arch/x86/traps.c
xen/include/asm-x86/time.h